package com.learn.project2.config;

import com.learn.project2.config.customException.NoChooseCategoryL1Exception;
import com.learn.project2.config.customException.RealmFailException;
import com.learn.project2.config.customException.ShipException;
import com.learn.project2.utils.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @description: 异常处理类
 * @author 王力
 * @date 2022-01-08 09:29
 * @version 1.0
 */
@RestControllerAdvice
public class Project2ExceptionHandler {


    /**
     * @description: 发货异常
     * @param: [e]
     * @return: com.learn.project2.utils.Result
     * @author 王力
     * @date: 2022-01-12 20:09:49
     */
    @ExceptionHandler(ShipException.class)
    public Result shipFail(ShipException e){
        e.printStackTrace();
        return Result.fail("未选择快递公司");
    }


    /**
     * @description: 数字格式异常
     * @param: [e]
     * @return: com.learn.project2.utils.Result
     * @author 王力
     * @date: 2022-01-08 09:31:02
     */
    @ExceptionHandler(NumberFormatException.class)
    public Result numberFormat(NumberFormatException e){
        e.printStackTrace();
        return Result.fail("数字格式不正确");
    }
/**
 * @description: 未选择一级类目异常
 * @param:
 * @return:
 * @author 亓永杰
 * @date: 2022-01-08 23:41
 */
    @ExceptionHandler(NoChooseCategoryL1Exception.class)
    public Result NoChooseCategoryL1(){
        return Result.fail("未选择一级目录，如没有请创建新的一级目录");
    }

    @ExceptionHandler(RealmFailException.class)
    public Result RealmFail(){
        return Result.fail("认证失败");
    }

    /**
     * @description: 所有异常的保底处理
     * @param: []
     * @return: com.learn.project2.utils.Result
     * @author 王力
     * @date: 2022-01-12 09:43:22
     */
    @ExceptionHandler(Exception.class)
    public Result Exception(Exception e){
        e.printStackTrace();
        return Result.fail("服务器繁忙，请稍候");
    }




}
